﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.IO;

namespace LuckyBingoRcon.Players
{
	/// <summary>
	/// Known team names:
	/// mp_array        - Black Ops Vs Spetsnaz
    /// mp_cairo        - Op 40 Vs Tropas
    /// mp_cosmodrome   - Black Ops Vs Spetsnaz
	/// mp_cracked      - SOG Vs NVA
	/// mp_crisis       - Op 40 Vs Tropas
    /// mp_duga         - Black Ops Vs Spetsnaz
    /// mp_firingrange  - Op 40 Vs Tropas
    /// mp_hanoi        - SOG Vs NVA
    /// mp_havoc        - SOG Vs NVA
    /// mp_mountain     - Black Ops Vs Spetsnaz
    /// mp_nuked        - Black Ops Vs Spetsnaz
    /// mp_radiation    - Black Ops Vs Spetsnaz
    /// mp_russianbase  - Black Ops Vs Spetsnaz
    /// mp_villa        - Op 40 Vs Tropas
	/// </summary>
	public class TeamLookup
	{
		private Dictionary<string, string> teamOne = new Dictionary<string, string>();
		private Dictionary<string, string> teamTwo = new Dictionary<string, string>();

		public TeamLookup()
		{
			FileInfo teamFile = new FileInfo("Configs\\teamList.cfg");
            if(teamFile.Exists)                  // Found the Team List Config file, load from there
            {
                string[] configStrings = File.ReadAllLines(teamFile.FullName);
                string[] args;
                foreach(string entry in configStrings)
                {
                    if(entry.StartsWith("//"))
                        continue;
                    args = Regex.Split(entry, ";");
                    if(!args.Length.Equals(3))
                        continue;
                    teamOne.Add(args[0], args[2]);
                    teamTwo.Add(args[0], args[1]);
                }
            }
            else                                // Can't find Team List Config file, use map defaults (Maps as of 9 November 2010)
            {
                //RconForm.Console.WriteLine("Could not find file: <Root>\\Configs\\teamList.cfg");
                teamTwo.Add("mp_array", "Black Ops");
			    teamTwo.Add("mp_cairo",		    "Op 40");
			    teamTwo.Add("mp_cosmodrome",    "Black Ops");
			    teamTwo.Add("mp_cracked",		"SOG");
			    teamTwo.Add("mp_crisis",		"Op 40");
			    teamTwo.Add("mp_duga",			"Black Ops");
			    teamTwo.Add("mp_firingrange",   "Op 40");
			    teamTwo.Add("mp_hanoi",		    "SOG");
			    teamTwo.Add("mp_havoc",		    "SOG");
			    teamTwo.Add("mp_mountain",		"Black Ops");
			    teamTwo.Add("mp_nuked",	        "Black Ops");
			    teamTwo.Add("mp_radiation",	    "Black Ops");
			    teamTwo.Add("mp_russianbase",   "Black Ops");
			    teamTwo.Add("mp_villa",		    "Op 40");
                teamOne.Add("mp_array",		    "Spetsnaz");
			    teamOne.Add("mp_cairo",		    "Tropas");
			    teamOne.Add("mp_cosmodrome",    "Spetsnaz");
			    teamOne.Add("mp_cracked",		"NVA");
			    teamOne.Add("mp_crisis",		"Tropas");
			    teamOne.Add("mp_duga",			"Spetsnaz");
			    teamOne.Add("mp_firingrange",   "Tropas");
			    teamOne.Add("mp_hanoi",		    "NVA");
			    teamOne.Add("mp_havoc",		    "NVA");
			    teamOne.Add("mp_mountain",		"Spetsnaz");
			    teamOne.Add("mp_nuked",	        "Spetsnaz");
			    teamOne.Add("mp_radiation",	    "Spetsnaz");
			    teamOne.Add("mp_russianbase",   "Spetsnaz");
			    teamOne.Add("mp_villa",		    "Tropas");
            }
		}

		/// <summary>
		/// NOT IMPLEMENTED, haven't decided on a file format
		/// </summary>
		/// <param name="mapFile"></param>
        public TeamLookup(string mapFile)
		{
			// not implemented
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="uglyName" (map name)></param>
		/// <returns>NULL if team one name is not known</returns>
		public string GetTeamOneName(string uglyName)
		{
            if (teamOne.ContainsKey(uglyName))
			{
                return teamOne[uglyName];
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 
		/// </summary>
        /// <param name="uglyName" (map name)></param>
        /// <returns>NULL if team two name is not known</returns>
        public string GetTeamTwoName(string uglyName)
		{
            if (teamTwo.ContainsKey(uglyName))
			{
                return teamTwo[uglyName];
			}
			else
			{
				return null;
			}
		}

        /*public bool IsValidName(string name)
        {
            if (name.Equals("Any"))
                return true;
            return (pretty2Ugly.ContainsKey(name) || ugly2Pretty.ContainsKey(name));
        }

        public string[] GetPrettyNames() 
        { 
            string[] sa = new string[pretty2Ugly.Keys.Count]; 
            pretty2Ugly.Keys.CopyTo(sa, 0); 
            return sa; 
        }    
        
        public string[] GetUglyNames() 
        { 
            string[] sa = new string[ugly2Pretty.Keys.Count]; 
            ugly2Pretty.Keys.CopyTo(sa, 0); 
            return sa; 
        }*/
	}
}
